package com.trade.common.annontation;

import java.lang.reflect.Field;

/**
 * @Desc: 注解处理器
 * @Version: v1.0 2018/3/23 17:59
 * @Author: zfb
 * @JDK Version: 1.8.0_51
 */
public class FruitInfoUtil {
    public static void getFruitInfo(Class<?> clazz) {

        String strFruitName=" 水果名称：";
        String strFruitColor=" 水果颜色：";
        String strFruitProvicer="供应商信息：";

        Field[] fields = clazz.getDeclaredFields();
        if (fields != null && fields.length > 0) {
            for (Field field : fields) {
                if (field.isAnnotationPresent(FruitName.class)) {
                    FruitName fruitName = field.getAnnotation(FruitName.class);
                    strFruitName += fruitName.value();
                    System.out.println(strFruitName);
                } else if (field.isAnnotationPresent(FruitColor.class)) {
                    FruitColor fruitColor= field.getAnnotation(FruitColor.class);
                    strFruitColor += fruitColor.fruitColor().toString();
                    System.out.println(strFruitColor);
                } else if (field.isAnnotationPresent(FruitProvider.class)) {
                    FruitProvider fruitProvider= field.getAnnotation(FruitProvider.class);
                    strFruitProvicer +=" 供应商编号："+fruitProvider.id()+" 供应商名称："+fruitProvider.name()+" 供应商地址："+fruitProvider.address();
                    System.out.println(strFruitProvicer);
                }
            }
        }
    }
}
